<include file="../header" />
<div class="wrapper">
    <div class="header text-center font-16">
        智能报修
        <div class="iconfont icon-zuo go_back"></div>
    </div>
    <div class="history-list">

        <div class="repair-list gray2">
            <select name="community_id" id="community_id">
                {BEESCRM:$community}
            </select>
            <div class="iconfont icon-zuo-copy"></div>
        </div>
        <div class="repair-list gray2">
            <select name="building_id" id="building_id">
                {BEESCRM:$building}
            </select>
            <div class="iconfont icon-zuo-copy"></div>
        </div>
        <div class="repair-list gray2">
            <select name="floor_id" id="floor_id">
                {BEESCRM:$floor}
            </select>
            <div class="iconfont icon-zuo-copy"></div>
        </div>
        <div class="repair-list ">
            <input type="text" placeholder="请输入房间号" id="room_name" value="{BEESCRM:$address.room_name}">
        </div>

        <if condition="$address['address_detail']" >
        <div class="repair-list ">
            <input type="text" placeholder="请输入详细地址" id="address_detail" value="{BEESCRM:$address.address_detail}">
        </div>
        </if>

        <div class="repair-list ">
            <input type="text" placeholder="请输入姓名" id="user_name" value="{BEESCRM:$address.user_name}">
        </div>
        <div class="repair-list ">
            <input type="text" placeholder="请输入联系方式" id="mobile" value="{BEESCRM:$address.mobile}">
        </div>
    </div>
    <a href="#" class="btn text-center save" id="save_address">保存</a>
</div>
<input type="hidden" id="address_id" value="{BEESCRM:$address.address_id}">
<input type="hidden" id="is_submit" value="0">
<script src="/assets/repaireast/js/layer.js"></script>
<script src="/assets/repaireast/js/public.js"></script>
<script type="text/javascript">
    $('#community_id').change(function(){
        $.ajax({
            type:'post',
            url:"/Repaireast/RepaireastRepair/ajaxGetBuildingOption",
            dataType:'json',
            data:{
                'community_id' : $('#community_id').val()
            },
            success:function(data){
                if(data.status=='S'){
                    $('#building_id').html(data.data);
                    $('#floor_id').html("<option value=''>请选择楼层</option>");
                    $('#room_id').html("<option value=''>请选择房号</option>");
                }
            }
        });
    });
    $('#building_id').change(function(){
        $.ajax({
            type:'post',
            url:"/Repaireast/RepaireastRepair/ajaxGetFloorOption",
            dataType:'json',
            data:{
                'building_id' : $('#building_id').val()
            },
            success:function(data){
                if(data.status=='S'){
                    $('#floor_id').html(data.data);
                    $('#room_id').html("<option value=''>请选择房号</option>");
                }
            }
        });
    });
    $('#floor_id').change(function(){
        $.ajax({
            type:'post',
            url:"/Repaireast/RepaireastRepair/ajaxGetRoomOption",
            dataType:'json',
            data:{
                'floor_id' : $('#floor_id').val()
            },
            success:function(data){
                if(data.status=='S'){
                    $('#room_id').html(data.data);
                }
            }
        });
    });

    $('#save_address').click(function(){
        var community_id = $('#community_id').val();
        if (community_id < 1){
            fm.alert('请选择园区！');
            return false;
        }
        var building_id = $('#building_id').val();
        if (building_id < 1){
            fm.alert('请选择楼幢！');
            return false;
        }
        var floor_id = $('#floor_id').val();
        if (floor_id < 1){
            fm.alert('请选择楼层！');
            return false;
        }
//        var room_id = $('#room_id').val();
//        if (room_id < 1){
//            fm.alert('请选择房号！');
//            return false;
//        }
        var room_name = $('#room_name').val();
        if (room_name < 1){
            fm.alert('请填写房号！');
            return false;
        }

        // 详细地址
        var address_detail = $('#address_detail').val();

        var user_name = $('#user_name').val();
        if (!user_name){
            fm.alert('请填写姓名！');
            return false;
        }
        var mobile = $('#mobile').val();
        if (!mobile){
            fm.alert('请填写联系方式！');
            return false;
        }
        var reg = /^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
        if(!reg.test(mobile)){
            fm.alert('手机号格式有误！');
            return false;
        }
        var is_submit = $('#is_submit').val();
        if (is_submit == 0){
            $('#is_submit').val(1);
            $.ajax({
                type:'post',
                url:"/Repaireast/RepaireastRepair/doEditAddress/type/"+"{BEESCRM:$type}",
                dataType:'json',
                data:{
                    'community_id' : community_id,
                    'community_name' : $('#community_id option:selected').text(),
                    'building_id' : building_id,
                    'building_name' : $('#building_id option:selected').text(),
                    'floor_id' : floor_id,
                    'floor_name' : $('#floor_id option:selected').text(),
                    //'room_id' : room_id,
                    //'room_name' : $('#room_id option:selected').text(),
                    'room_name' : room_name,
                    'address_detail' : address_detail,
                    'user_name' : user_name,
                    'mobile' : mobile,
                    'address_id' : $('#address_id').val()
                },
                success:function(data){
                    if(data.status=='S'){
                        fm.alert('操作成功!');
                        setTimeout(function(){
                            window.location.href=data.url;
                        },2000);
                    }else{
                        fm.alert(data.message);
                    }
                    $('#is_submit').val(0);
                },
                error:function(){
                    fm.alert('通讯失败，请稍后再试');
                    $('#is_submit').val(0);
                }
            });
        }
    });
</script>

<include file="../footer" />